package com.group.elmboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.group.elmboot.po.Business;

@Mapper
public interface BusinessMapper {

	@Select("select * from business where orderTypeId=#{orderTypeId} order by businessId")
	public List<Business> listBusinessByOrderTypeId(Integer orderTypeId);
	
	@Select("select * from business where businessId=#{businessId}")
	public Business getBusinessById(Integer businessId);
	
	@Select("select * from business order by Sales desc")
	public List<Business> getBusinessOrderBySalesDesc();
	
	@Update("update business set Sales =Sales+1 where businessId =#{businessId}")
	public int salesPlus(Integer businessId);
	
	@Update("update business set businessName=#{businessName}, businessAddress=#{businessAddress}, "
			+ "businessExplain=#{businessExplain}, businessImg=#{businessImg}, orderTypeId=#{orderTypeId},"
			+ "starPrice=#{starPrice}, deliveryPrice=#{deliveryPrice} where businessId =#{businessId}")
	public int updateBusinessInfo(Business business);
	
	@Insert("insert into business(businessName,businessAddress,businessExplain,businessImg,orderTypeId,starPrice,deliveryPrice,manager) "
			+ "values(#{businessName}, #{businessAddress}, #{businessExplain}, #{businessImg}, #{orderTypeId}, #{starPrice}, #{deliveryPrice},#{manager})")
	@Options(useGeneratedKeys=true,keyProperty="businessId",keyColumn="businessId")
	public int insertBusinessInfo(Business business);
	
	@Select("select * from business where manager=#{manager} order by businessId")
	public List<Business> listBusinessByManagerId(String manager);
	
	@Delete("delete from business where businessId=#{businessId}")
	public int deleteBusinessById(Integer businessId);
	
	@Select("select * from business where starPrice<=#{starPrice} and deliveryPrice<=#{deliveryPrice} order by Sales desc")
	public List<Business> listBusinessByConditions(Business business);
	
	@Select("select count(*) from business where businessName=#{businessName} and not businessId =#{businessId}")
	public int checkBusinessNameDuplicate(Business business);
	
	@Select("select count(*) from business where businessName=#{businessName}")
	public int checkBusinessNameDuplicateNull(Business business);
	
	@Select("select * from business where businessName like #{businessName,jdbcType=VARCHAR}")
	public List<Business> searching(String businessName);
}
